import time

from flask import Flask
from routes.todo import main as todo_routes
from routes.index import main as index_routes
from routes.comment import main as comment_routes
from routes.blog import main as blog_routes

# web application
app = Flask(__name__)
# 设置secret_key 来使用flask自带的session
app.secret_key = 'random string'
# 注册蓝图
app.register_blueprint(todo_routes, url_prefix='/todo')
app.register_blueprint(index_routes)
app.register_blueprint(comment_routes, url_prefix='/comment')
app.register_blueprint(blog_routes, url_prefix='/blog')


# 增加过滤器
@app.template_filter('format_date')
def format_date(timestamp):
    timeStruct = time.localtime(timestamp)
    res = time.strftime('%Y-%m-%d %H:%M:%S', timeStruct)
    return res


# 运行代码
if __name__ == '__main__':
    config = dict(
        debug=True,
        host='0.0.0.0',
        port=2000,
    )
    app.run(**config)
